<template>
    <el-autocomplete v-model="infoName"
                     valueKey="name"
                     @blur="checkCurrentId"
                     :trigger-on-focus="true"
                     :fetch-suggestions="querySearchAsync"
                     @mouseenter.native="isMouseEnter=true"
                     @mouseleave.native="isMouseEnter=false"
                     :placeholder="placeholder" @select="handleSelectDic">
        <i class="el-input__icon" :class="infoName&&isMouseEnter&&!disabled?'el-icon-error':'el-icon-edit'" @click="handleClear"
           slot="suffix"></i>
        <template slot-scope="props">
            <div class="name">{{ props.item.resourceNo }}</div>
        </template>
    </el-autocomplete>
</template>

<script>
    import CommonSearchInput from './common'
    import { getJobVehicleList } from "@/api/baseResource/baseResource";

    export default {
        mixins: [CommonSearchInput],
        methods: {
            // 异步搜索信息
            querySearchAsync(queryString, cb) {
                getJobVehicleList({
                    search_LIKE_resourceNo:queryString,
                    'iDisplayLength': this.iDisplayLength
                }).then((reponse) => {
                    cb(reponse.data.aaData)
                })
            },
            handleClear() {
                if (this.infoName&&!this.disabled) {
                    this.infoName = ''
                    this.$emit('select', '')
                    this.$emit('selectName', '')
                    this.$emit('selectId', '')
                }
            },
            handleSelectDic(item) {
                this.$emit('matchRecord', Object.assign({}, item))
                this.$emit('select', item.resourceNo)
                this.$emit('selectName', item.resourceNo)
                this.$emit('selectId', item.resourceNo)
                this.infoName=item.resourceNo
            },
        },
    }
</script>
